﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Example07.aspx.cs" Inherits="Chapter32.Example07" %>

<!DOCTYPE html>

<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>代码清单 32-7 禁用内容缓存</title>
    <meta name="author" content="Adam Freeman" />
    <meta name="description" content="A simple example" />
    <link rel="shortcut icon" type="image/x-icon" href="favicon.ico" />
</head>
<body>
    <div>
        <button>Example01.Apples</button>
        <button>Example01.Cherries</button>
        <button>Example01.Bananas</button>
    </div>
    <div id="target">Press a button</div>
    <script>
        var buttons = document.getElementsByTagName("button");
        for (var i = 0; i < buttons.length; i++) {
            buttons[i].onclick = handleButtonPress;
        }

        function handleButtonPress(e) {
            var httpRequest = new XMLHttpRequest();
            httpRequest.onreadystatechange = handleResponse;
            httpRequest.open("GET", e.target.innerHTML + ".aspx");
            httpRequest.setRequestHeader("Cache-Control", "no-cache");
            httpRequest.send();
        }

        function handleResponse(e) {
            if (e.target.readyState == e.target.DONE && e.target.status == 200) {
                document.getElementById("target").innerHTML = e.target.responseText;
            }
        }
    </script>
</body>
</html>
